package com.chaopei.day37thym.controller;

import com.chaopei.day37thym.entity.Cool;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Author yws
 * @Date 2022/4/21 11:31
 */
@Controller
public class MyCOntroller {
    /*
    HttpServletRequest/Model/Map/ModelMap，前端可以直接通过请求对象名称可以拿到
    HttpSession禽蛋要通过session对象获取。
    */
    @RequestMapping("/")
    public String go(Model model) {
        model.addAttribute("pic", "img");//将数据携带给前端
        Cool cool = new Cool(1008,"小美");
        model.addAttribute("cool",cool);
        List<String> list = new ArrayList<>();
        list.add("tom");
        list.add("bean");
        list.add("mary");
        model.addAttribute("list",list);
        return "index";
    }

    @RequestMapping("/play")
    @ResponseBody
    public List<String> play(HttpServletRequest request,Model model) {
        List<String> list = new ArrayList<>();
        list.add("tom");
        list.add("bean");
        list.add("mary");
        String temp = request.getParameter("msg");
        list.add(temp);
        return list;
    }
}
